{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="wap.php?app=order&act=index"><i class="return"></i></a>
	<div class="titleView">订单详情</div>
</div>

<div class="main-top order-detail">
	<div class="statusView ge-bottom">
		<span class="status{$data->status}">{$data->status_name}</span>
		订单号 {$data->order_sn}
	</div>
	<div class="infoView">
		<div>{$data->name}　{$data->mobile}</div>
		{if $data->shop_id>0 && $data->beautician_id>0}<div><span>指定美容师</span>{$data->beautician_name}</div>{/if}
		<div><span>预约时间</span>{$data->service_time}</div>
		<div><span>服务地址</span>{$data->full_address}</div>
	</div>
	<div class="nameView ge-bottom">
		{if $data->shop_id>0}
		<i class="shop"></i>{$data->shop_name}
		{else if $data->beautician_id>0}
		<i class="master"></i>{$data->beautician_name}
		{/if}
	</div>
	<div class="projectView ge-bottom">
		{foreach from=$data->projects name=p item=p}
		<div class="project">
			<div class="pic" style="background-image:url({$p->project_pic});"></div>
			{$p->project_name}
		</div>
		{/foreach}
	</div>
	<div class="view ge-bottom">
		<span>{if $data->pay_method=='yue'}余额/财富支付{else if $data->pay_method=='wxpay_h5'}微信支付{else if $data->pay_method=='wxpay'}微信支付{else if $data->pay_method=='alipay'}支付宝支付{else}套餐支付{/if}</span>支付方式
	</div>
	<div class="view">
		<span class="red">￥{$data->total_price}</span>实付金额
	</div>
	<div class="btnView {if $data->status==1 && $data->can_cancel_order==1 && $data->can_edit_time==1}btn-half{/if}">
		{if $data->status==0}<div><a class="pay" href="javascript:void(0)">去付款</a></div>{/if}
		{if $data->status==1}
		{if $data->can_edit_time==1}<div><a class="edit" href="javascript:void(0)" mid="{$data->id}" shop_id="{$data->shop_id}" beautician_id="{$data->beautician_id}" project_ids="{trim($data->project_ids,',')}" service_time="{$data->service_time}">修改时间</a></div>{/if}
		{if $data->can_cancel_order==1}<div><a class="gray cancel" href="javascript:void(0)" mid="{$data->id}">取消订单</a></div>{/if}
		{/if}
		{if $data->status==4}
		<div><a class="green comment" href="javascript:void(0)" mid="{$data->id}">去评价</a></div>
		<!--<div><a href="javascript:void(0)">再次预约</a></div>-->
		{/if}
		{if $data->status==5}<!--<div><a href="javascript:void(0)">再次预约</a></div>-->{/if}
		{if $data->status==0}
		<form action="wap.php?app=order&act=order_pay" method="post">
		<input type="hidden" name="order_sn" value="{$data->order_sn}" />
		<input type="hidden" name="price" value="{$data->total_price}" />
		<input type="hidden" name="body" value="i美-项目订单" />
		<input type="hidden" name="pay_method_name" value="微信支付" />
		</form>
		{/if}
	</div>
</div>

{include file="footer.html"}
<script>
var service_time_g = [];
function checkBind(){
	$('.btnView a.pay').each(function(){
		if(!!$(this).data('bind'))return true;
		$(this).data('bind', true).click(function(){
			$(this).parent().find('form').submit();
		});
	});
	$('.btnView a.comment').each(function(){
		if(!!$(this).data('bind'))return true;
		$(this).data('bind', true).click(function(){
			location.href = 'wap.php?tpl=comment.index&id='+$(this).attr('mid')+'&url='+location.href.urlencode();
		});
	});
	$('.btnView a.cancel').each(function(){
		if(!!$(this).data('bind'))return true;
		$(this).data('bind', true).click(function(){
			if(!confirm('我们已经为了您的美丽做好准备了，您真的不来了么？'))return false;
			$.postJSON('api.php?app=order&act=cancel', { id:$(this).attr('mid') }, function(json){
				if(json.error!=0){
					$.overloadError(json.msg);
					return;
				}
				location.href = location.href;
			});
		});
	});
	$('.btnView a.edit').each(function(){
		if(!!$(this).data('bind'))return true;
		$(this).data('bind', true).click(function(){
			if(!confirm('每个订单只有一次修改时间的机会，您确认要修改么？'))return false;
			getServiceTime($(this), function(){
				var g = service_time_g;
				$('.faceView .dates a').click(function(){
					$('.faceView .dates a').removeClass('x');
					$(this).addClass('x');
					var html = '', r = g[$(this).index()].schedule;
					for(var i=0; i<r.length; i++){
						html += '<a href="javascript:void(0)" timestamp="'+r[i].timestamp+'" '+(r[i].available!=0?'class="x"':'')+'>\
							<div class="view"><span>'+r[i].hour+'</span></div>\
						</a>';
					}
					$('.faceView .dateView').html(html);
					$('.faceView .dateView a.x').click(function(){
						setServiceTime.call(this);
					});
				});
				$('.faceView .dateView a.x').click(function(){
					setServiceTime.call(this);
				});
				$('.faceView .buttonView .btn').click(function(){
					var mid = $(this).attr('mid'), service_time = $(this).attr('service_time');
					if(!!!service_time){
						$.overloadError('请选择服务时间');
						return;
					}
					$.overload(null);
					$.postJSON('api.php?app=order&act=edit_time', { id:mid, service_time:service_time }, function(json){
						if(json.error!=0){
							$.overloadError(json.msg);
							return;
						}
						$.overloadSuccess('修改成功');
						removeFaceView();
						location.href = location.href;
					});
				});
			});
		});
	});
}
$(function(){
	checkBind();
});

function bindFaceView(faceView){
	var titleView = $('.faceView .navBar .titleView');
	titleView.css('margin-left', -titleView.width()/2);
	$('.faceView .navBar .left').click(function(){
		removeFaceView(faceView);
	});
	$('.faceView').each(function(){
		var height = $.window().height;
		if($(this).outerHeight(true)<height)$(this).height(height);
	});
}
function removeFaceView(faceView){
	if(typeof faceView == 'undefined')faceView = '.faceView';
	$(faceView).removeClass('x');
	setTimeout(function(){ $(faceView).remove() }, 400);
}

function setServiceTime(){
	$('.faceView .dateView a').removeClass('this');
	$(this).addClass('this');
	var timestamp = $(this).attr('timestamp').toDate('yyyy-mm-dd')+' '+$.trim($(this).text());
	$('.faceView .timeView span').html(timestamp);
	$('.faceView .buttonView .btn').attr('service_time', timestamp);
}
function getServiceTime(_this, fn){
	var type_id = (!isNaN(_this.attr('shop_id')) && parseInt(_this.attr('shop_id'))>0) ? 2 : 1;
	$.overload(null);
	$.getJSON('api.php?app=home&act=schedule&shop_id='+_this.attr('shop_id')+'&beautician_id='+_this.attr('beautician_id')+'&project_ids='+_this.attr('project_ids')+'&type_id='+type_id, function(json){
		$.overload(false);
		if(json.error==1){
			alert(json.msg);
			return;
		}
		var g = json.data;
		if(!$.isArray(g)){
			alert('缺少数据');
			return;
		}
		service_time_g = g;
		var html = '<div class="faceView gr">\
						<div class="navBar">\
							<a class="left" href="javascript:void(0)"><i class="return"></i></a>\
							<div class="titleView">服务时间</div>\
						</div>\
						<div class="main-top home-schedule">\
							<div class="dates">\
								<div class="datesUL">';
									for(var i=0; i<g.length; i++){
										html += '<a href="javascript:void(0)" '+(!i?'class="x"':'')+'>\
											<div class="view">\
												<span>'+g[i].name+'</span>\
												<div>'+g[i].date+'</div>\
											</div>\
										</a>';
									}
								html += '</div>\
							</div>\
							<div class="dateView">';
								var r = g[0].schedule;
								for(var i=0; i<r.length; i++){
									html += '<a href="javascript:void(0)" timestamp="'+r[i].timestamp+'" '+(r[i].available!=0?'class="x"':'')+'>\
										<div class="view"><span>'+r[i].hour+'</span></div>\
									</a>';
								}
							html += '<div class="clear"></div></div>\
							<div class="timeView ge-top ge-bottom"><div>服务时间</div><span>'+_this.attr('service_time')+'</span></div>\
							<div class="buttonView"><a href="javascript:void(0)" class="btn pass" mid="'+_this.attr('mid')+'">确认修改</a></div>\
						</div>\
					</div>';
		$('body').append(html);
		setTimeout(function(){
			$('.faceView').addClass('x');
			var a = $('.faceView .datesUL a').width(Math.floor($('.faceView').width()/7));
			$('.faceView .datesUL').width(a.width()*a.length);
		}, 10);
		bindFaceView();
		fn(g);
	});
}
</script>